-
Notifications
You must be signed in to change notification settings - Fork 65
poc: Extensible Mapper using JavaScript #3650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
poc: Extensible Mapper using JavaScript #3650
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
The javascript examples have to be updated. For instance the syntax |
Though it seems that Optional Chaining is part of ES2020 (which means it should be supported by QuickJS, I confirmed on the WASM version of QuickJS at least), so that would be the most similar to your previous syntax (just adding a For example:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is my first round of review comments focussing purely on the pipeline APIs and not much of the rust infra code. Unfortunately, I'm having some trouble testing the feature due to some certificate misconfiguration preventing the mapper from even starting with the following error:
Jun 10 06:36:23 2a9636a9acc5 tedge-mapper[3107]: 2025-06-10T06:36:23.630655575Z ERROR Runtime: Actor MQTT-2 has finished unsuccessfully: ActorError(InvalidPrivateKey(InvalidCertificate(Other(OtherError(UnsupportedCertVersion)))))
Will provide additional usability feedback once that issue is resolved.
stages = [ | ||
{ filter = "add_timestamp.js" }, | ||
{ filter = "drop_stragglers.js", config = { max_delay = 60 } }, | ||
{ filter = "te_to_c8y.js", meta_topics = ["te/+/+/+/+/m/+/meta"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if stage-wise meta_topics
is really necessary or a pipe-line level meta_topics
would be sufficient (and simpler to maintain).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we want here is for the messages received on the meta topics to be directly delivered to the stage. The other stages have no way to do something meaningful with these messages (In this case, units for various measurement types).
A better name might be config_topics
.
stages = [ | ||
{ filter = "add_timestamp.js" }, | ||
{ filter = "drop_stragglers.js", config = { max_delay = 60 } }, | ||
{ filter = "te_to_c8y.js", meta_topics = ["te/+/+/+/+/m/+/meta"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expressing the correlation between the input_topic
and meta_topic
with wildcards appears slightly inaccurate/misleading. For example, when the above definition is applied on a te/+/+/+/+/m/temperature
measurement, the corresponding meta_topic
should have only been te/+/+/+/+/m/temperature/meta
. But with the wildcard te/+/+/+/+/m/+/meta
subscription, it covers the meta topics of other measurements like m/pressure/meta
, m/humidity/meta
etc as well. Wondering if we should introduce some sort of variable substitution syntax like m/{m_type}
and m/{m_type}/meta
so that this correlation is better expressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you propose seems too specific to this specific example (adding units to measurements leveraging the meta
topics as defined by thin-edge). Sure the script (here te_to_c8y.js
) has to appropriately match data and meta data, but why should the generic mapper enforce that from the outside?
Though I couldn't fix the cert issue, I've moved on by completely disabling auth settings. |
|
||
stages = [ | ||
{ filter = "add_timestamp.js" }, | ||
{ filter = "circuit-breaker.js", tick_every_seconds = 1, config = { stats_topic = "te/error", too_many = 10000, message_on_too_many = { topic = "te/device/main///a/too-many-messages", payload = "too many messages" }, message_on_back_to_normal = { topic = "te/device/main///a/too-many-messages", payload = "back to normal" } } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line highlights pain points with the current configuration format.
- There are two levels of config which is confusing.
tick_every_second
is used by the engine, whileconfig.too_many
is passed to the script. Flattening theconfig
might be simpler. - TOML inline tables are intended to appear on a single line. Leading to painfully long lines as here.
- Passing a JSON payload to the filter config is not straightforward. Currently the engine expects a string and the JS filter has to stringyfy the payload.
fba7bdd
to
2e41d5e
Compare
2e41d5e
to
e759966
Compare
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
5d6a90a
to
f2ca7b5
Compare
For now, the bindgen feature is enable for all targets. One could consider to use bindings shipped with quickjs when available. See https://github.com/delskayn/rquickjs?tab=readme-ov-file#supported-platforms Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Proposed changes
This POC explores quickJS as an alternative to:
A thin-edge mapper that can be extended by users with mapping rules implemented in JavaScript.
Features:
MQTT sub| filter-1 | filter-2 | ... | filter-n | MQTT pub
Criteria:
Examples:
Types of changes
Paste Link to the issue
Checklist
just prepare-dev
once)just format
as mentioned in CODING_GUIDELINESjust check
as mentioned in CODING_GUIDELINESFurther comments